﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;

using JSIF_WCFServer.Model;
using System.IO;

namespace JSIF_WCFServer.Server
{    
    /// <summary>
    /// A service which allows a client to read a book, or fetch information about it
    /// </summary>
    [ServiceContract(SessionMode = SessionMode.Allowed)] 
    public interface IBookshelfReader
    {
        /// <summary>
        /// Returns a list of the books visible to the user on this server
        /// </summary>
        /// <returns>a list of the books visible to the user on this server</returns>
        [WebInvoke(UriTemplate = "/", BodyStyle=WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method="GET")]
        [OperationContract] 
        List<Book> ListStories();

        /// <summary>
        /// Returns the history of changes made to the book visible to the user
        /// </summary>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <returns>the history of changes made to the book visible to the user</returns>
        [WebInvoke(UriTemplate = "/{shortname}/history", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        [OperationContract]
        List<HistoryItem> GetHistoryForBook(String shortname);

        /// <summary>
        /// Returns the version of the book which is playable online (or a media file if specified)
        /// </summary>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <param name="fileRef">An optional reference to a specific media file, if no file is specified this should return the root html file for the story</param>
        /// <returns>the version of the book which is playable online (or a media file if specified)</returns>
        [WebInvoke(UriTemplate = "/{shortname}/published/online/{*fileRef}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        [OperationContract]
        Stream GetPublishedOnlineVersion(String shortname, String fileRef);

        /// <summary>
        /// Returns the version of the book which is playable offline
        /// </summary>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <returns>the version of the book which is playable offline</returns>
        [WebInvoke(UriTemplate = "/{shortname}/published/download", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        [OperationContract]
        Stream GetPublishedOffineVersion(String shortname);

        /// <summary>
        /// Returns a zip archive of the book with the current version and all media files included
        /// </summary>
        /// <remarks>
        /// You would use this version of the book to export the book to another server
        /// </remarks>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <returns>a zip archive of the book with the current version and all media files included</returns>
        [WebInvoke(UriTemplate = "/{shortname}/published/archive", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        [OperationContract]
        Stream GetPublishedArchiveVersion(String shortname);

        /// <summary>
        /// Returns the meta data for a book
        /// </summary>
        /// <param name="shortname">The server specific shortname of the book</param>
        /// <returns>the meta data for a book</returns>
        [WebInvoke(UriTemplate = "/{shortname}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        [OperationContract]
        Book GetBookInfo(String shortname);    
    }
}
